<?php

include("global.php");

$pagetitle=" - Administration - User Groups";
$links=" > Administration > User Groups";

include ("header.php");

include ("admin_header.php");

if($userloggedinarray[15]!=="administrator"){
   unset($tplcontent);
   $tplcontent['notice'].="Must be logged in as administrator to use control panel!";
   echo template('notice',$tplcontent);
}else{

if(!$addusergroups&&!isset($editusergroups)&&!isset($deleteusergroups)&!$addusergroups2&&!isset($editusergroups2)){
unset($tplcontent);
 $usergroupsarray=getdata("$configarray[1]/usergroups.php");

   for($n=0;$n<count($usergroupsarray);$n++){

    $tplcontent['usergroupslist'].="<b>$usergroupsarray[$n]</b>\n";
    $tplcontent['usergroupslist'].=" | <a href=\"admin_usergroups.php?editusergroups=$n\">Edit</a>";
    $tplcontent['usergroupslist'].=" | <a href=\"admin_usergroups.php?deleteusergroups=$n\">Delete</a>";

    $tplcontent['usergroupslist'].="<br><br>";

   }//end usergroups loop
   $tplcontent['addnew'].="<a href=\"admin_usergroups.php?addusergroups=1\">Add new</a>";

   echo template('adminusergroupsview',$tplcontent);
 }

 if(isset($editusergroups)){

 $usergroupsarray=getdata("$configarray[1]/usergroups.php");

 $tplcontent['formheader'].="<form action=\"admin_usergroups.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"editusergroups2\" value=\"$editusergroups\" size=40>";

 $tplcontent['usergroupid'].="Edit User Group $editusergroups";

 $tplcontent['usergroupname'].="<input type=text name=\"usergroupname\" value=\"$usergroupsarray[$editusergroups]\" size=40 class=\"forminput\">";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Update\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";

 echo template('adminusergroupedit',$tplcontent);
 }

 if(isset($editusergroups2)){


 writedata("$configarray[1]/usergroups.php",$usergroupname,$editusergroups2);

   unset($tplcontent);
   $tplcontent['notice'].="User Group edited - <a href=\"admin_usergroups.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if($addusergroups=="1"){

 $tplcontent['formheader'].="<form action=\"admin_usergroups.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"addusergroups\" value=\"2\" size=40>";

 $tplcontent['usergroupname'].="<input type=text name=\"usergroupname\" size=40 class=\"forminput\">";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Add User Group\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";

 echo template('adminusergroupadd',$tplcontent);
 }

 if($addusergroups=="2"){
 $usergroupsarray=getdata("$configarray[1]/usergroups.php");
 $end=count($usergroupsarray);

 writedata("$configarray[1]/usergroups.php",$usergroupname,$end);

   unset($tplcontent);
   $tplcontent['notice'].="User Group added - <a href=\"admin_usergroups.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if(isset($deleteusergroups)){
 deletedata("$configarray[1]/usergroups.php",$deleteusergroups);

   unset($tplcontent);
   $tplcontent['notice'].="User Group $deleteusergroups deleted - <a href=\"admin_usergroups.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

}
include("admin_footer.php");

include("footer.php");

?>